<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <title>内部邮箱</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <base href="http://localhost:8888/"/>
  <link rel="stylesheet" href="css/font.css">
  <link rel="stylesheet" href="css/weadmin.css">
</head>
<body>
<div class="weadmin-body">
  <fieldset class="layui-elem-field layui-field-title">
    <legend>内部邮箱</legend>
  </fieldset>
  <form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item" style="width: 50%">
      <label class="layui-form-label">主题</label>
      <div class="layui-input-block">
        <input type="text" name="mailTitle" th:value="${savedMail.mailTitle}" autocomplete="off" placeholder="请输入邮件主题" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item" style="width: 90%">
      <label class="layui-form-label">接收人</label>
      <div class="layui-input-inline" style="width: 35%">
        <select name="acceptUserId">
          <option value=""></option>
          <option th:each="user:${userList}" th:value="${user.id}" th:selected="${user.id} == ${savedMail.acceptUserId}">【[[${user.department}]]】 【[[${user.name}]]】 【[[${user.email}]]】</option>
        </select>
      </div>
    </div>

      <div class="layui-form-item">
      <label class="layui-form-label">邮件类型</label>
      <div class="layui-input-inline">
        <select name="mailType">
          <option value="工作" th:selected="${savedMail.mailType} == '工作'">工作</option>
          <option value="闲聊" th:selected="${savedMail.mailType} == '闲聊'">闲聊</option>
          <option value="建议" th:selected="${savedMail.mailType} == '建议'">建议</option>
          <option value="其他" th:selected="${savedMail.mailType} == '其他'">其他</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item" pane="" style="width: 25%">
      <label class="layui-form-label">是否匿名</label>
      <div class="layui-input-block">
        <input type="radio" name="anonymous" value="0" title="实名" th:checked="${savedMail.anonymous} == 0">
        <input type="radio" name="anonymous" value="1" title="匿名" th:checked="${savedMail.anonymous} == 1">
      </div>
    </div>
    <div class="layui-form-item layui-form-text" style="width: 50%">
      <label class="layui-form-label">邮件正文</label>
      <div class="layui-input-block">
        <label>
          <textarea name="content" placeholder="请输入内容" class="layui-textarea" th:text="${savedMail.content}">
          </textarea>
        </label>
      </div>
    </div>
    <div class="layui-form-item">
      <button class="layui-btn" lay-submit="" lay-filter="send">发送邮件</button>
      <button class="layui-btn" lay-submit="" lay-filter="save">保存草稿</button>
    </div>
  </form>
</div>

<script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
<script>
  layui.use(['form', 'jquery'], function() {
    var form = layui.form
            ,layer = layui.layer,
            $ = layui.jquery;

    //监听提交
    form.on('submit(send)', function(data){
      // 发送ajax
      $.ajax({
        url: 'http://localhost:8888/member/life/mailBox/send',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify(data.field),
        success: function (res) {
          console.log('success');
          if (res.result === "SUCCESS") {
            layer.alert("发送成功", { icon: 6 });
          } else {
            layer.msg(res.message);
          }
        }
      });
      return false;
    });

    //监听保存
    form.on('submit(save)', function(data){
      // 发送ajax
      $.ajax({
        url: 'http://localhost:8888/member/life/mailBox/save',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify(data.field),
        success: function (res) {
          console.log('success');
          if (res.result === "SUCCESS") {
            layer.alert("保存成功", { icon: 6 });
          } else {
            layer.msg(res.message);
          }
        }
      });
      return false;
    });
  });
</script>

</body>
</html>